﻿using DependencyInjectionHelperLib.Eunms;

namespace DependencyInjectionHelperLib.Attributes
{
    /// <summary>
    /// DependencyInjection 容器注册特性，将当前类注册到 DependencyInjection 容器中。
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class DIRegistrationAttribute : Attribute
    {
        public Lifetimes Lifetime { get; set; }
        public string PageKey { get; set; }
        public Type[] InterfaceTypes { get; set; }

        /// <summary>
        /// 将服务类注册到 IServiceCollection 容器中的特性
        /// </summary>
        /// <param name="lifetime">注册的生命周期，默认值为单例模式</param>
        /// <param name="pageKey">用于导航的key值</param>
        /// <param name="interfaceTypes">注册的服务接口</param>
        public DIRegistrationAttribute(
            Lifetimes lifetime = Lifetimes.Singleton,
            string pageKey = "",
            params Type[] interfaceTypes
        )
        {
            Lifetime = lifetime;
            PageKey = pageKey;
            InterfaceTypes = interfaceTypes;
        }
    }
}